<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateEnterprisesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('enterprises', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable(false)->comment('企业名称');
            $table->string('contact')->nullable(true)->comment('企业联系人');
            $table->string('contact_phone')->nullable(true)->comment('联系电话');
            $table->string('info')->nullable(true)->comment('基本信息');
            $table->string('remarks')->nullable(true)->comment('备注');
            $table->json('type')->nullable(true)->comment('企业类型:车企、储能、保险公司');
            $table->timestamps();
        });

        Schema::create('user_has_enterprises', function (Blueprint $table) {
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('enterprise_id');
            $table->primary(['user_id', 'enterprise_id'], 'user_has_enterprises_user_id_enterprise_id_primary');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('enterprises');
        Schema::dropIfExists('user_has_enterprises');
    }
}
